package com.ruicar.afs.cloud.apply.business.service.impl;

import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruicar.afs.cloud.apply.business.condition.ApplyOrderLeadingCondition;
import com.ruicar.afs.cloud.apply.business.mapper.ApplyOrderLeadingMapper;
import com.ruicar.afs.cloud.apply.business.service.ApplyOrderLeadingService;
import com.ruicar.afs.cloud.apply.common.entity.ApplyOrderInfo;
import com.ruicar.afs.cloud.apply.pre.loan.vo.ApplyOrderLeadingVo;
import com.ruicar.afs.cloud.common.core.security.util.SecurityUtils;
import com.ruicar.afs.cloud.common.core.security.vo.RoleVo;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 订单放款service实现类
 *
 * @author 耿继辉
 */
@Service
public class ApplyOrderLeadingServiceImpl extends ServiceImpl<ApplyOrderLeadingMapper, ApplyOrderInfo> implements ApplyOrderLeadingService {
    /**
     * 多条件获取订单放款信息
     *
     * @param condition
     * @return
     */
    @Override
    public IPage<List<ApplyOrderLeadingVo>> getOrderLeadingInfo(Page page, ApplyOrderLeadingCondition condition) {
        // 用户名
        condition.setCreateBy(SecurityUtils.getUsername());
        JSONArray jsonArray = SecurityUtils.getUser().getUserExtInfo().getJSONArray("deptIds");
        if(jsonArray!=null){
            // 部门列表
            condition.setDeptIds(jsonArray.toJavaList(String.class));
        }
        condition.setDeptId(String.valueOf(SecurityUtils.getUser().getDeptId()));
        JSONArray roleArray = SecurityUtils.getUser().getUserExtInfo().getJSONArray("roles");
        if(roleArray != null){
            List<RoleVo> roleList = roleArray.toJavaList(RoleVo.class);
            condition.setRoleList(roleList);
        }
        return this.baseMapper.getOrderLeadingInfo(page,condition);
    }
}
